home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interplay's Learn to Program Basic (Review Copy)
/
Learn to Program Basic Review Copy (Interplay)(June 23, 1998).ISO
/
pc
/
ltpbasic
/
projects
/
hangman.bas
< prev
next >
Wrap
BASIC Source File
|
1998-04-01
|
4KB
|
223 lines
rem Hangman
rem by Scott Mathews
rem August 18, 1997
cls
let wordcount = 25
let maxwordsize = 10
let bodypart = 0
let gallowscolor = 45
let bodycolor = 60
let letterfound = false
let alive = true
let rightrow = 12
let wrongcol = 33
let wrongrow = 3
rem set up and fill the word array
dim hangman$ (wordcount)
for count = 1 to wordcount
read hangman$ (count)
next count
rem grab a random word from the array
let pos = random (1, wordcount)
let word$ = hangman$ (pos)
rem draw the correct number of spaces for the word
let length = Len(word$)
let column = 1
for Scount = 1 to length
position column*2, rightrow
print "_"
let column = column +1
next Scount
rem draw the gallows
for I = 10 to 50 step 10
color gallowscolor
fillrect 10+I,190-I to 20+I, 200-I
next I
line 70,140 to 180,140
line 85,60 to 85,140
line 85,60 to 125,60
line 125,60 to 125,70
rem take each letter in the word
rem and put it into an array location
dim letter$ (maxwordsize)
for Lcount = 1 to maxwordsize
let letter$(Lcount) = Mid$(word$,Lcount,1)
next Lcount
rem main loop
while alive = true
let letterfound = false
rem Ask the player for a guess
guesscheck:
position 5,1
print " "
position 5,1
input "What is your guess? ", guess$
if len(guess$) <> 1 then
position 5,1
print " "
position 5,1
print "Guess one letter at a time!"
Sound("CARHORN")
sleep 20
position 5,1
print " "
goto guesscheck
endif
rem is the player's guess correct?
rem if it is, print it on one of the spaces
for correct = 1 to maxwordsize
if guess$ = letter$(correct)then
let letterfound = true
position correct*2, rightrow
rem add a sound effect here
Sound "BOUNCE"
sleep 5
print guess$
let length = length - 1
if length = 0 then
gosub victory
endif
endif
next correct
rem is the player's guess incorrect?
rem if it is, print it in the 'wrong' column
if letterfound = false then
position wrongcol, wrongrow
rem put a buzz sound here
Sound "GAMESHOW"
print guess$
let wrongcol = wrongcol+1
if wrongcol >= 36 then
let wrongcol = 33
let wrongrow = wrongrow+1
endif
let bodypart = bodypart+1
gosub drawman
endif
wend
end
drawman:
color bodycolor
rem draw the head
if bodypart = 1 then
circle 125,80, 10
endif
rem draw the neck
if bodypart = 2 then
line 125,90 to 125,100
endif
rem draw the arms
if bodypart = 3 then
line 115,100 to 135,100
endif
rem draw the torso
if bodypart = 4 then
line 125,100 to 125,115
endif
rem draw the legs
if bodypart = 5 then
line 125,115 to 110,130
line 125,115 to 140,130
endif
rem draw the appendages
if bodypart = 6 then
circle 112,100,3
circle 138, 100,3
circle 107,130,3
circle 141,130,3
endif
rem draw the face
if bodypart = 7 then
line 120,75 to 123,78
line 123,75 to 120,78
line 130,75 to 127,78
line 127,75 to 130,78
circle 125,84,3
gosub gameover
endif
return
rem this is the subroutine if the player loses
gameover:
let alive = false
rem play a death sound here
Sleep 10
Sound "Squeak"
Sleep 5
Sound "Arrow"
Sleep 10
Sound "Scream"
sleep 20
cls
position 10,0
print "You have lost!"
print
print "Would you like to see the"
input "word you were trying to guess?", answer$
if left$(answer$,1) = "y" then
position 14,10
print "The word was:"
let leng = len(word$)
let x = int((40-leng)/2)
position x,12
print word$
else
position 10,10
print "Okay. Thanks for playing."
endif
return
rem this is the subroutine if the player wins
victory:
let alive = false
Sleep 5
cls
position 12,0
print "You have won!"
position 14,10
print "The word was:"
let leng = len(word$)
let x = int((40-leng)/2)
position x,12
print word$
rem play a victory sound here
Sound "Crowd"
sleep 20
return
rem lots of carriage returns here to hide
rem the guess words
rem here's the words for the game
data condition, sprite, happy, frenzy, safety
data major, laboratory, notebook, zephyr, allocate
data doorknob, basketball, zeal, wreath, apply
data irritate, conceal, zealot, patience, morale
data value, sudden, foible, huge, gargantuan